<?php

namespace core\lib;

class conf
{

    public static $conf = [];
    public static function get($name,$file)
    {
        if(isset(self::$conf[$file])){
            // 存在缓存
            return self::$conf[$file][$name];
        }else{
            $path = IMOOC.'/core/config/'.$file.'.php';
            if(is_file($path)){
                $conf = include $path;
                if(isset($conf[$name])){
                    self::$conf[$file] = $conf;
                    return $conf[$name];
                }else{
                    throw new \Exception('没有这个配置项'.$name);
                }
            }else{
                throw new \Exception('不存在该配置文件'.$path);
            }
        }
    }


    // 获取全部参数
    public static function all($file)
    {
        if(isset(self::$conf[$file])){
            // 存在缓存
            return self::$conf[$file];
        }else{
            $path = IMOOC.'/core/config/'.$file.'.php';
            if(is_file($path)){
                $conf = include $path;
                self::$conf[$file] = $conf;
                return $conf;
            }else{
                throw new \Exception('不存在该配置文件'.$path);
            }
        }
    }

}